package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.enums.EnableStatusEnum;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServeItemUpsertReqDTO;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Autowired
    private IServeService iServeService;

    @GetMapping("/page")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO dto) {
        PageResult<ServeResDTO> pr = iServeService.page(dto);
        return pr;
    }

/**
 * TODO
 * 新增要降低数据库操作次数
 * */
    @PostMapping("/batch")
    public void add(@RequestBody List<ServeUpsertReqDTO> listDto) {
       iServeService.add(listDto);
    }

    @PutMapping("/{id}")
    public void editPrice(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        iServeService.editPrice(id, price);
    }

    @PutMapping("/onSale/{id}")
    public void onSale(@PathVariable("id") Long id) {
        iServeService.editStatus(id);
    }


    /**
     * 下架
     *
     * */
    @PutMapping("/offSale/{id}")
    public void offSale(@PathVariable("id") Long id) {
        iServeService.offStatus(id);
    }


    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id) {
        iServeService.delete(id);
    }


    @PutMapping("/onHot/{id}")
    public void onHot(@PathVariable("id") Long id) {
        iServeService.changeHotStatus(id, EnableStatusEnum.ENABLE.getStatus());
    }

    @PutMapping("/offHot/{id}")
    public void offHot(@PathVariable("id") Long id) {
        iServeService.changeHotStatus(id, EnableStatusEnum.DISABLE.getStatus());
    }

}
